package com.openthinks.joyniproject.dao.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.openthinks.joyniproject.dao.BaseDao;
import com.openthinks.joyniproject.dao.TestDao;
import com.openthinks.joyniproject.model.PageModel;
import com.openthinks.joyniproject.utils.SQLConfigLoader;

@Repository
public class TestDaoImpl implements TestDao {

	@Autowired
	private BaseDao baseDao;

	@Override
	public int create(Map<String, Object> data) {

		String sql = SQLConfigLoader.getSQL("testCreate");
		
		int id = baseDao.insert(sql, data,"id");
		
		return id;
	}

	@Override
	public PageModel query(Map<String, Object> data) {

		String sql = SQLConfigLoader.getSQL("testQuery");
		
		Integer start = 0;
		Integer limit = 15;
		if (data.get("start") != null) {
			start = Integer.valueOf(data.get("start").toString());
		}
		if (data.get("limit") != null) {
			limit = Integer.valueOf(data.get("limit").toString());
		}
		
		PageModel result = baseDao.queryForPageModel(sql, start, limit, data);
		
		return result;
	}

	@Override
	public void delete(Map<String, Object> paramMap) {
		String sql = SQLConfigLoader.getSQL("testDelete");
		
		baseDao.delete(sql, paramMap);
	}
	
}
